package co.chuangdian.oflauncher.folders;

import org.json.JSONArray;
import android.annotation.SuppressLint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import cn.onekit.CONFIG;
import cn.onekit.JSON;
import co.chuangdian.oflauncher.folders.FoldersFragment.ViewHolder;


//出了点问题
public class FolderListAdapter extends BaseAdapter  {

	FoldersFragment context;
	JSONArray folders = JSON.parses((String) CONFIG.get("folders"));
	
	@Override
	public int getCount() {
		return folders.length();
	}

	@Override
	public Object getItem(int position) {
		try {
			return folders.getJSONObject(position);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		// Folder_bean folder_bean = folder_list.get(position);
		ViewGroup row = null;
		ViewHolder mHolder;
		
		/*
		try {		
			JSONObject folder = folders.optJSONObject(position);
			row = (ViewGroup) View.inflate(context., R.layout.folders_row, null);
			row.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, ACTIVITY.dp2px(80)));
			mHolder = new ViewHolder();
			// 把布局文件中所有组件的对象封装至ViewHolder对象中
			mHolder.name = (TextView) row.findViewById(R.id.iconText);
			mHolder.icon = (ImageView) row.findViewById(R.id.iconImageView);
			mHolder.cover = (ImageView) row.findViewById(R.id.coverImageView);
			// 把ViewHolder对象封装至View对象中
			row.setTag(mHolder);
			Bitmap cover = ASSET.loadImage(folder.optString("cover"), false);
			Bitmap icon = ASSET.loadImage(folder.optString("icon"), true);
			mHolder.cover.setImageBitmap(cover);
			mHolder.name.setText(folder.getString("name"));
			mHolder.icon.setImageBitmap(icon);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		*/
		
		
		return row;
	}
	
	
}
